package miiteen.twoexploit.controller;

import io.swagger.annotations.Api;
import miiteen.common.json.JsonUtil;
import miiteen.common.utils.JacksonMapper;
import miiteen.core.result.ResultMessage;
import miiteen.core.result.ResultMessageTool;
import miiteen.data.beans.PageBounds;
import miiteen.hr.pubconfig.CurrentHrInfo;
import miiteen.hr.user.beans.UserUserInfo;
import miiteen.sys.base.controller.BaseAction;
import miiteen.sys.login.bean.UserShiro;
import miiteen.sys.login.utils.LoginUtil;
import miiteen.twoexploit.beans.Favorite;
import miiteen.twoexploit.beans.Instructor;
import miiteen.twoexploit.beans.Regulations;
import miiteen.twoexploit.service.FavoriteService;
import miiteen.twoexploit.service.InstructorService;
import miiteen.twoexploit.service.RegulationsService;
import net.sf.json.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Name: lzhg_two_instructor
 * Des: -controller
 * Author: qyp
 * Date: 2021-10-20
 * 收藏夹
 */
@Api(tags = "收藏夹")
@RestController
@RequestMapping(value = "/two/favorite")
@CrossOrigin
public class FavoriteController extends BaseAction {

	@Autowired
	private FavoriteService favoriteService;

	/**
	 * 兰州海关作业指导书
	 */
	@Autowired
	private InstructorService instructorService;

	/**
	 * 兰州海关规章制度
	 */
	@Autowired
	private RegulationsService regulationsService;




	@RequestMapping(value = "/list")
	public ModelAndView list() {
	    //设置列表关联JSP页面
		ModelAndView mv = new ModelAndView("twoexploit/favorite/FavoriteList");
        //自行设置默认查询条件
        
		return mv;
	}
    

    @RequestMapping("/search")
    @ResponseBody
    public String search(@RequestBody JSONObject jsonObject) {
        //获取查询条件
        PageBounds pageBounds = JsonUtil.jsonobjToObj(jsonObject.getJSONObject("pagecon"), PageBounds.class);
        Map<String, Object> map = JsonUtil.jsonobjToMap(jsonObject.getJSONObject("searchcon"));


        //获取登入用户角色
		UserShiro.ShiroUser shiroUser= LoginUtil.getCurUser();
		UserUserInfo user= CurrentHrInfo.getUserInfo(shiroUser);
		String deptName = user.getTrueName();
		map.put("deptName", deptName);

        //查询数据
        List<Favorite> list = favoriteService.findListByMap(map, pageBounds);
        if (list != null && list.size() > 0) {
            return JacksonMapper.getListToJson(ResultMessageTool.Success(String.valueOf(pageBounds.getTotal()), list));
        } else {
            return JacksonMapper.getListToJson(ResultMessageTool.Error(""));
        }
    }



/*	@RequestMapping("/getone")
	@ResponseBody
    public   ResultMessage<Object>  getone( @RequestParam Long  id,@RequestParam int typecode) {

		Favorite favorite = new Favorite();


	}*/


}